package com.dmp.storm.bolt.db;

import com.dmp.common.mybatis.ExtendService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;
import java.util.Map;

/**
 * @ClassName MyBatisInsertBatchBolt
 * @Description
 *
 * @author sunzy
 * @date 2016年4月18日 下午5:30:21
 * @version 1.0
 *
 */
public class MyBatisInsertBatchBolt extends MapCacheBolt {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2718627510354718799L;

	private static Logger logger = LoggerFactory.getLogger(MyBatisInsertBatchBolt.class);

	private ApplicationContext appContext;
	private ExtendService service;
	// 配置参数
	// private String extServiceName = "billFieldExtService";
	private String serviceName ;
	private String serviceConfig ;

	@Override
	public void prepare() {
		super.prepare();
		appContext = new ClassPathXmlApplicationContext(serviceConfig);
		service = appContext.getBean(serviceName, ExtendService.class);

		logger.info("extend service:{}", service);
	}
	
	@Override
	public void processBatch(List<Map<String, Object>> list) {
		final List<Map<String, Object>> record = list;
		if (service != null) {
			// System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + record);
			if (record != null && record.size() > 0) {
				service.extend(record);
			}
		}
	}

	public String getServiceName() {
		return serviceName;
	}

	public void setServiceName(String serviceName) {
		this.serviceName = serviceName;
	}

	public String getServiceConfig() {
		return serviceConfig;
	}

	public void setServiceConfig(String serviceConfig) {
		this.serviceConfig = serviceConfig;
	}
}
